
//JS
layui.use(['table', 'layer','form'], function() {
    var layer = layui.layer,
        table = layui.table,
        form = layui.form,
        $ = layui.$;

    //绑定批量导入按钮
    $('#reviewersAssign-adds-btn').click(function () {
        layer.open({
            type: 1
            , offset: 0
            , content: $("#reviewersAssign-adds-box")
            , end: function () {
                $('#reviewersAssign-adds-box').css('display','none');
            }
        });
    });
    //绑定批量分配评阅人按钮
    $('#reviewersAssign-assigns-btn').click(function () {
        layer.open({
            type: 1
            , offset: 0
            , content: $("#reviewersAssign-assigns-box")
            , end: function () {
                $('#reviewersAssign-assigns-box').css('display','none');
            }
        });
    });
    //绑定批量取消分配按钮
    $('#reviewersAssign-cancels-btn').click(function () {
        layer.open({
            type: 1
            , offset: 0
            , content: $("#reviewersAssign-cancels-box")
            , end: function () {
                $('#reviewersAssign-cancels-box').css('display','none');
            }
        });
    });
    <!-- 动态表格-分配评阅教师 -->
    table.render({
        elem: '#reviewersAssign-table',
        toolbar: true,
        page: true,
        height: 700,
        url: "/getAllTeacher",
        cols: [
            [ //标题栏
                {field: 'tNO', title: '工号', sort: true, width: 120, align: 'center'},
                {field: 'password', title: '密码', width: 90, align: 'center'},
                {field: 'name', title: '真实姓名', width: 120, align: 'center'},
                {field: 'sex', title: '性别', width: 90, align: 'center'},
                {field: 'collegeId', title: '学院编号', align: 'center'},
                {field: 'department', title: '部门', width: 110, align: 'center'},
                {field: 'post', title: '职位', width: 110, align: 'center'},
                {field: 'role', title: '角色名', width: 90, align: 'center'},
                {field: 'tel', title: '联系方式', width: 90, align: 'center'},
                {field: 'email', title: '邮箱', align: 'center'},
                {title: '操作', width: 120, toolbar: '#reviewersAssignBtn', align: 'center'}
            ]
        ]
    });
    //监听行内工具事件
    table.on('tool(reviewersAssign-table)', function (obj) {
        let data = obj.data;
        if (obj.event === 'reviewersA') {//分配评阅教师
            layer.confirm('确认分配该教师为评阅教师吗？',function () {
               let tno = data.tNO;
               // console.log(tno)

                let loadPage = layui.layer.load(0, {shade: [0.5, '#fff']});
               $.ajax({
                   url: "/reviewerAssign"
                   ,type: 'post'
                   ,data: {
                       tno: tno
                   }
                   ,dataType: 'json'
                   ,success: function (data) {//调用接口成功
                       console.log(data)
                       if (data === 1001) {//评阅人不存在，进行新增操作
                           layer.close(loadPage);
                           layer.closeAll('page');
                           layui.layer.msg('分配成功！', {offset: '300px', time: 2500, anim: 0});
                           table.reload('reviewersAssign-table', {});
                       } else if (data === 1002) {
                           layui.layer.close(loadPage);
                           layui.layer.alert('分配失败！数据未能成功插入数据库！');
                       } else if (data === 1003) {
                           layui.layer.close(loadPage);
                           layui.layer.alert('分配失败！该教师已被分配过！');
                       }
                   }
               });
            });
            return false;//阻止表单跳转。如果需要表单跳转，去掉这段即可。
        }
    });


    <!-- 动态表格-学生 -->
    table.render({
        elem: '#studentsAssign-table',
        toolbar: true,
        page: true,
        height: 700,
        url: "/getAllStudent",
        cols: [
            [ //标题栏
                {field: 'sNO', title: '学号', sort: true, width: 120, align: 'center'},
                {field: 'password', title: '密码', width: 90, align: 'center'},
                {field: 'name', title: '真实姓名', width: 120, align: 'center'},
                {field: 'sex', title: '性别', width: 90, align: 'center'},
                {field: 'collName', title: '学院', align: 'center'},
                {field: 'majorName', title: '专业', width: 110, align: 'center'},
                {field: 'classes', title: '班级', width: 110, align: 'center'},
                {field: 'role', title: '角色名', width: 90, align: 'center'},
                {field: 'tel', title: '联系方式', width: 90, align: 'center'},
                {field: 'email', title: '邮箱', align: 'center'},
                {title: '操作', width: 120, toolbar: '#studentsAssignBtn', align: 'center'}
            ]
        ]
    });
    //监听行内工具事件
    table.on('tool(studentsAssign-table)', function (obj) {
        let data = obj.data;
        if (obj.event === 'studentsA') {//学生分配页面
            layer.open({
                title: '学生分配'
                , offset: 10
                , skin: 'layui-layer-rim'
                , area: ['1080px','500px']
                , type: 1
                , shadeClose: true
                , content: $('#studentsAssign-assigns-box')
                , success: function(layerObj) {
                    $(".layui-layer-shade").appendTo(layerObj.parent());
                    $("#sno").val(data.sNO);
                }
                , end: function () {
                    $('#studentsAssign-assigns-box').css('display','none');
                }
            });
        }
    });
    //学生分配页面数据表-评阅教师选择
    table.render({
        elem: '#reviewer-choose-table',
        toolbar: true,
        page: true,
        width: 950,
        height: 400,
        url: "/reviewerAllQuery",
        where: {type: 1},
        cols: [
            [ //标题栏
                {field: 'id', title: '编号', sort: true, width: 225, align: 'center'},
                {field: 'name', title: '角色名', width: 225, align: 'center'},
                {field: 'tno', title: '工号', width: 320, align: 'center'},
                {title: '操作', width: 180, toolbar: '#studentsAssign-chooseBtn', align: 'center'}
            ]
        ]
    });
    //监听行内工具事件
    table.on('tool(reviewer-choose-table)', function (obj) {
        let data = obj.data;
        if (obj.event === 'studentsSure') {//为学生分配评阅教师
            layer.confirm('确认分配该教师？',function () {
                let tno = data.tno;
                let sno = $("#sno").val();
                console.log(tno)
                console.log(sno)

                let loadPage = layui.layer.load(0, {shade: [0.5, '#fff']});
                $.ajax({
                    url: "/gradingAdd"
                    ,type: 'post'
                    ,data: {
                        tno: tno,
                        sno: sno
                    }
                    ,dataType: 'json'
                    ,success: function (data) {//调用接口成功
                        console.log(data)
                        if (data === 1001) {//该学生的评阅教师不存在，进行新增操作
                            layer.close(loadPage);
                            layer.closeAll('page');
                            layui.layer.msg('分配成功！', {offset: '300px', time: 2500, anim: 0});
                            table.reload('reviewersAssign-table', {});
                        } else if (data === 1002) {//该学生已有评阅教师
                            layui.layer.close(loadPage);
                            layui.layer.alert('分配失败！数据未能成功插入数据库！');
                        } else if (data === 1003) {//该学生已有评阅教师
                            layui.layer.close(loadPage);
                            layui.layer.alert('分配失败！该学生已被分配过！');
                        }
                    }
                });
            });
            return false;//阻止表单跳转。如果需要表单跳转，去掉这段即可。
        }
    });





    //批量分配弹出层内数据表
    table.render({
        elem: '#reviewersAssign-assigns-table',
        toolbar: true,
        page: true,
        cols: [
            [
                {field: 'name', title: '用户名', width: 220},
                {field: 'id', title: '学号/工号', width: 220},
                {field: 'sCount', title: '已分配人数', width: 240},
                {title: '操作', width: 180, toolbar: '#reviewersAssign-as-Btn'}
            ]
        ],
        data: [
            {"name": "学生01","role": "学生","doTime": "2020-10-10","doType": "通过"}
        ]
    });



});
